{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python练习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（一）有四个数字：1、2、3、4，能组成多少个互不相同且无重复数字的三位数？各是多少？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 有两种解题思路：\n",
    "* a.利用for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "102\n",
      "103\n",
      "104\n",
      "105\n",
      "106\n",
      "107\n",
      "108\n",
      "109\n",
      "120\n",
      "123\n",
      "124\n",
      "125\n",
      "126\n",
      "127\n",
      "128\n",
      "129\n",
      "130\n",
      "132\n",
      "134\n",
      "135\n",
      "136\n",
      "137\n",
      "138\n",
      "139\n",
      "140\n",
      "142\n",
      "143\n",
      "145\n",
      "146\n",
      "147\n",
      "148\n",
      "149\n",
      "150\n",
      "152\n",
      "153\n",
      "154\n",
      "156\n",
      "157\n",
      "158\n",
      "159\n",
      "160\n",
      "162\n",
      "163\n",
      "164\n",
      "165\n",
      "167\n",
      "168\n",
      "169\n",
      "170\n",
      "172\n",
      "173\n",
      "174\n",
      "175\n",
      "176\n",
      "178\n",
      "179\n",
      "180\n",
      "182\n",
      "183\n",
      "184\n",
      "185\n",
      "186\n",
      "187\n",
      "189\n",
      "190\n",
      "192\n",
      "193\n",
      "194\n",
      "195\n",
      "196\n",
      "197\n",
      "198\n",
      "201\n",
      "203\n",
      "204\n",
      "205\n",
      "206\n",
      "207\n",
      "208\n",
      "209\n",
      "210\n",
      "213\n",
      "214\n",
      "215\n",
      "216\n",
      "217\n",
      "218\n",
      "219\n",
      "230\n",
      "231\n",
      "234\n",
      "235\n",
      "236\n",
      "237\n",
      "238\n",
      "239\n",
      "240\n",
      "241\n",
      "243\n",
      "245\n",
      "246\n",
      "247\n",
      "248\n",
      "249\n",
      "250\n",
      "251\n",
      "253\n",
      "254\n",
      "256\n",
      "257\n",
      "258\n",
      "259\n",
      "260\n",
      "261\n",
      "263\n",
      "264\n",
      "265\n",
      "267\n",
      "268\n",
      "269\n",
      "270\n",
      "271\n",
      "273\n",
      "274\n",
      "275\n",
      "276\n",
      "278\n",
      "279\n",
      "280\n",
      "281\n",
      "283\n",
      "284\n",
      "285\n",
      "286\n",
      "287\n",
      "289\n",
      "290\n",
      "291\n",
      "293\n",
      "294\n",
      "295\n",
      "296\n",
      "297\n",
      "298\n",
      "301\n",
      "302\n",
      "304\n",
      "305\n",
      "306\n",
      "307\n",
      "308\n",
      "309\n",
      "310\n",
      "312\n",
      "314\n",
      "315\n",
      "316\n",
      "317\n",
      "318\n",
      "319\n",
      "320\n",
      "321\n",
      "324\n",
      "325\n",
      "326\n",
      "327\n",
      "328\n",
      "329\n",
      "340\n",
      "341\n",
      "342\n",
      "345\n",
      "346\n",
      "347\n",
      "348\n",
      "349\n",
      "350\n",
      "351\n",
      "352\n",
      "354\n",
      "356\n",
      "357\n",
      "358\n",
      "359\n",
      "360\n",
      "361\n",
      "362\n",
      "364\n",
      "365\n",
      "367\n",
      "368\n",
      "369\n",
      "370\n",
      "371\n",
      "372\n",
      "374\n",
      "375\n",
      "376\n",
      "378\n",
      "379\n",
      "380\n",
      "381\n",
      "382\n",
      "384\n",
      "385\n",
      "386\n",
      "387\n",
      "389\n",
      "390\n",
      "391\n",
      "392\n",
      "394\n",
      "395\n",
      "396\n",
      "397\n",
      "398\n",
      "401\n",
      "402\n",
      "403\n",
      "405\n",
      "406\n",
      "407\n",
      "408\n",
      "409\n",
      "410\n",
      "412\n",
      "413\n",
      "415\n",
      "416\n",
      "417\n",
      "418\n",
      "419\n",
      "420\n",
      "421\n",
      "423\n",
      "425\n",
      "426\n",
      "427\n",
      "428\n",
      "429\n",
      "430\n",
      "431\n",
      "432\n",
      "435\n",
      "436\n",
      "437\n",
      "438\n",
      "439\n",
      "450\n",
      "451\n",
      "452\n",
      "453\n",
      "456\n",
      "457\n",
      "458\n",
      "459\n",
      "460\n",
      "461\n",
      "462\n",
      "463\n",
      "465\n",
      "467\n",
      "468\n",
      "469\n",
      "470\n",
      "471\n",
      "472\n",
      "473\n",
      "475\n",
      "476\n",
      "478\n",
      "479\n",
      "480\n",
      "481\n",
      "482\n",
      "483\n",
      "485\n",
      "486\n",
      "487\n",
      "489\n",
      "490\n",
      "491\n",
      "492\n",
      "493\n",
      "495\n",
      "496\n",
      "497\n",
      "498\n",
      "501\n",
      "502\n",
      "503\n",
      "504\n",
      "506\n",
      "507\n",
      "508\n",
      "509\n",
      "510\n",
      "512\n",
      "513\n",
      "514\n",
      "516\n",
      "517\n",
      "518\n",
      "519\n",
      "520\n",
      "521\n",
      "523\n",
      "524\n",
      "526\n",
      "527\n",
      "528\n",
      "529\n",
      "530\n",
      "531\n",
      "532\n",
      "534\n",
      "536\n",
      "537\n",
      "538\n",
      "539\n",
      "540\n",
      "541\n",
      "542\n",
      "543\n",
      "546\n",
      "547\n",
      "548\n",
      "549\n",
      "560\n",
      "561\n",
      "562\n",
      "563\n",
      "564\n",
      "567\n",
      "568\n",
      "569\n",
      "570\n",
      "571\n",
      "572\n",
      "573\n",
      "574\n",
      "576\n",
      "578\n",
      "579\n",
      "580\n",
      "581\n",
      "582\n",
      "583\n",
      "584\n",
      "586\n",
      "587\n",
      "589\n",
      "590\n",
      "591\n",
      "592\n",
      "593\n",
      "594\n",
      "596\n",
      "597\n",
      "598\n",
      "601\n",
      "602\n",
      "603\n",
      "604\n",
      "605\n",
      "607\n",
      "608\n",
      "609\n",
      "610\n",
      "612\n",
      "613\n",
      "614\n",
      "615\n",
      "617\n",
      "618\n",
      "619\n",
      "620\n",
      "621\n",
      "623\n",
      "624\n",
      "625\n",
      "627\n",
      "628\n",
      "629\n",
      "630\n",
      "631\n",
      "632\n",
      "634\n",
      "635\n",
      "637\n",
      "638\n",
      "639\n",
      "640\n",
      "641\n",
      "642\n",
      "643\n",
      "645\n",
      "647\n",
      "648\n",
      "649\n",
      "650\n",
      "651\n",
      "652\n",
      "653\n",
      "654\n",
      "657\n",
      "658\n",
      "659\n",
      "670\n",
      "671\n",
      "672\n",
      "673\n",
      "674\n",
      "675\n",
      "678\n",
      "679\n",
      "680\n",
      "681\n",
      "682\n",
      "683\n",
      "684\n",
      "685\n",
      "687\n",
      "689\n",
      "690\n",
      "691\n",
      "692\n",
      "693\n",
      "694\n",
      "695\n",
      "697\n",
      "698\n",
      "701\n",
      "702\n",
      "703\n",
      "704\n",
      "705\n",
      "706\n",
      "708\n",
      "709\n",
      "710\n",
      "712\n",
      "713\n",
      "714\n",
      "715\n",
      "716\n",
      "718\n",
      "719\n",
      "720\n",
      "721\n",
      "723\n",
      "724\n",
      "725\n",
      "726\n",
      "728\n",
      "729\n",
      "730\n",
      "731\n",
      "732\n",
      "734\n",
      "735\n",
      "736\n",
      "738\n",
      "739\n",
      "740\n",
      "741\n",
      "742\n",
      "743\n",
      "745\n",
      "746\n",
      "748\n",
      "749\n",
      "750\n",
      "751\n",
      "752\n",
      "753\n",
      "754\n",
      "756\n",
      "758\n",
      "759\n",
      "760\n",
      "761\n",
      "762\n",
      "763\n",
      "764\n",
      "765\n",
      "768\n",
      "769\n",
      "780\n",
      "781\n",
      "782\n",
      "783\n",
      "784\n",
      "785\n",
      "786\n",
      "789\n",
      "790\n",
      "791\n",
      "792\n",
      "793\n",
      "794\n",
      "795\n",
      "796\n",
      "798\n",
      "801\n",
      "802\n",
      "803\n",
      "804\n",
      "805\n",
      "806\n",
      "807\n",
      "809\n",
      "810\n",
      "812\n",
      "813\n",
      "814\n",
      "815\n",
      "816\n",
      "817\n",
      "819\n",
      "820\n",
      "821\n",
      "823\n",
      "824\n",
      "825\n",
      "826\n",
      "827\n",
      "829\n",
      "830\n",
      "831\n",
      "832\n",
      "834\n",
      "835\n",
      "836\n",
      "837\n",
      "839\n",
      "840\n",
      "841\n",
      "842\n",
      "843\n",
      "845\n",
      "846\n",
      "847\n",
      "849\n",
      "850\n",
      "851\n",
      "852\n",
      "853\n",
      "854\n",
      "856\n",
      "857\n",
      "859\n",
      "860\n",
      "861\n",
      "862\n",
      "863\n",
      "864\n",
      "865\n",
      "867\n",
      "869\n",
      "870\n",
      "871\n",
      "872\n",
      "873\n",
      "874\n",
      "875\n",
      "876\n",
      "879\n",
      "890\n",
      "891\n",
      "892\n",
      "893\n",
      "894\n",
      "895\n",
      "896\n",
      "897\n",
      "901\n",
      "902\n",
      "903\n",
      "904\n",
      "905\n",
      "906\n",
      "907\n",
      "908\n",
      "910\n",
      "912\n",
      "913\n",
      "914\n",
      "915\n",
      "916\n",
      "917\n",
      "918\n",
      "920\n",
      "921\n",
      "923\n",
      "924\n",
      "925\n",
      "926\n",
      "927\n",
      "928\n",
      "930\n",
      "931\n",
      "932\n",
      "934\n",
      "935\n",
      "936\n",
      "937\n",
      "938\n",
      "940\n",
      "941\n",
      "942\n",
      "943\n",
      "945\n",
      "946\n",
      "947\n",
      "948\n",
      "950\n",
      "951\n",
      "952\n",
      "953\n",
      "954\n",
      "956\n",
      "957\n",
      "958\n",
      "960\n",
      "961\n",
      "962\n",
      "963\n",
      "964\n",
      "965\n",
      "967\n",
      "968\n",
      "970\n",
      "971\n",
      "972\n",
      "973\n",
      "974\n",
      "975\n",
      "976\n",
      "978\n",
      "980\n",
      "981\n",
      "982\n",
      "983\n",
      "984\n",
      "985\n",
      "986\n",
      "987\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(10):\n",
    "        for z in range(10):\n",
    "            if (i!=j) and (j!=z) and (i!=z) :\n",
    "                print(i*100+j*10+z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999}\n"
     ]
    }
   ],
   "source": [
    "result={0}\n",
    "for i in range(1,10):\n",
    "    for j in range(10):\n",
    "        for z in range(10):\n",
    "            result.add(i*100+j*10+z)\n",
    "result.remove(0)            \n",
    "print(result)            "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（二）企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；利润高于10万元，低于20万元时，低于10万元的部分按10%提成，高于10万元的部分，可提成7.5%；20万到40万之间时，高于20万元的部分，可提成5%；40万到60万之间时高于40万元的部分，可提成3%；60万到100万之间时，高于60万元的部分，可提成1.5%，高于100万元时，超过100万元的部分按1%提成，从键盘输入当月利润I，求应发放奖金总数？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 分析题目两种方案解题\n",
    "* 首先逆序来\n",
    "* 利用条件语句计算看到底落在哪里档次进行详情计算\n",
    "* 利用列表进行对应处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入你的利润值1212222222222\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "12122319222.22"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input=  int(input('输入你的利润值'))\n",
    "temp=[1000000,600000,400000,200000,100000,0]\n",
    "rat=[0.01,0.015,0.03,0.05,0.75,0.1]\n",
    "result=0\n",
    "for i in range(6):\n",
    "    if input>temp[i]:\n",
    "        result+=(input-temp[i])*rat[i]\n",
    "        input=temp[i]\n",
    "result       "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（三）输入三个整数x,y,z，请把这三个数由小到大输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 通过集合排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入任意一个整数2\n",
      "输入任意一个整数4\n",
      "输入任意一个整数5\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[5, 4, 2]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list=[]\n",
    "x=int(input('输入任意一个整数'))\n",
    "y=int(input('输入任意一个整数'))\n",
    "z=int(input('输入任意一个整数'))\n",
    "list.append(x)\n",
    "list.append(y)\n",
    "list.append(z)\n",
    "list.sort(reverse=True)#注意排序反转\n",
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（四）将一个列表的数据复制到另一个列表中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, 4]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=[1,3,4,5,6]\n",
    "b=a[0:3]\n",
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（五）暂停一秒输出,并格式化当前时间。使用 time 模块的 sleep() 函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-02-08 15:26:37\n",
      "2018-02-08 15:26:47\n"
     ]
    }
   ],
   "source": [
    "import time \n",
    "print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())) \n",
    "time.sleep(10)\n",
    "print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（六）打印出所有的\"水仙花数\"，所谓\"水仙花数\"是指一个三位数，其各位数字立方和等于该数本身。例如：153是一个\"水仙花数\"，因为153=1的三次方＋5的三次方＋3的三次方。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153\n",
      "370\n",
      "371\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(10):\n",
    "        for z in range(10):\n",
    "            if i*100+j*10+z==pow(i,3)+pow(j,3)+pow(z,3): #pow（X,N）求X的N次幂\n",
    "                print(i*100+j*10+z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（七）输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入一行字符串121212sdfsdf  &&%%%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'串串含有字母：6，空格：2，数字：6，其他：5'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 =input('输入一行字符串')\n",
    "letter=0\n",
    "space=0\n",
    "number=0\n",
    "other=0\n",
    "for i in str1:\n",
    "    if i.isalpha():\n",
    "        letter+=1\n",
    "    elif i.isspace():\n",
    "        space+=1\n",
    "    elif i.isdigit():\n",
    "        number+=1\n",
    "    else :\n",
    "        other+=1\n",
    "'串串含有字母：{}，空格：{}，数字：{}，其他：{}'.format(letter,space,number,other)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "（八）一球从100米高度自由落下，每次落地后反跳回原高度的一半；再落下，求它在第10次落地时，共经过多少米？第10次反弹多高？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "* 算一下多少次才能够落地【递归】1/400 代表已经落地了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def test( src,number):\n",
    "    if src<=1/400 :\n",
    "        return number\n",
    "    else :\n",
    "        src=src/2\n",
    "        number+=1\n",
    "        print(number)\n",
    "        test(src,number)\n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n"
     ]
    }
   ],
   "source": [
    "num=test(200,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.390625\n"
     ]
    }
   ],
   "source": [
    "height=100\n",
    "sum_value=0\n",
    "list=[]\n",
    "for i in range(2,9):\n",
    "     height=height/2\n",
    "     list.append(height)\n",
    "print(min(list)/2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "298.4375\n"
     ]
    }
   ],
   "source": [
    "for i in list :\n",
    "    sum_value+=i\n",
    "print(sum_value*2+100)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
